<template>
  <div>
    <!-- 项目方案信息搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      :collapse="collapse"
      labelWidth="90"
      @filterChange="changeHandle"
    ></TopFilter>
    <!-- table -->
    <FilterTable
      height="250"
      ref="listModal"
      :columns="columns"
      :selectionType="selectType"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
      :onRowSelectChange="selectChange"
      columnsRef="projectOperating_projram_select_index_01"
    ></FilterTable>
    <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" type="primary">{{submit}}</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getLoginUser } from '@/api/cms-api/projectOperating/program/departmentInquire'; //获取登录信息
import { formatdateByDay } from '@/utils';
import { getOrgProjectProgramListAll } from '@/api/cms-api/projectOperating/program/departmentInquire';
import { getOemProjectProgramList } from '@/api/cms-api/projectOperating/program/oemInquire';
import { getDealerProjectProgramList } from '@/api/cms-api/projectOperating/program/inquire';
export default {
  mixins: [dictionary],
  props: {
    submit: {
      type: String,
      default: '确定'
    },
    selectType: {
      type: String,
      default: 'multiple'
    }
  },
  data() {
    return {
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchApi: null,
      fetchParams: { orgStatus: '25281002', programStatus: '25281002' }, //ipa 接口
      selectedRows: [] //选中营销素材
    };
  },
  methods: {
    async getUserInfo() {
      this.loginUser = await getLoginUser({});
      if (this.loginUser != null && this.loginUser != undefined) {
        if (this.loginUser.data.dataType == 10461001) {
          //经销商端登录
          this.fetchApi = getDealerProjectProgramList;
        } else {
          if (this.loginUser.data.orgType == 15061005) {
            //是事业部
            this.fetchApi = getOrgProjectProgramListAll;
          } else {
            this.fetchApi = getOemProjectProgramList;
          }
        }
        // if (this.loginUser.data.orgType == 15061007) {
        //办事处 获取父类ID，赋给orgId
        // this.orgId = this.loginUser.data.orgId;
        // }
      }
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'INPUT',
          label: '方案编号',
          fieldName: 'programCode',
          placeholder: '请输入',
          initialValue: '',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '方案名称',
          fieldName: 'programName',
          placeholder: '请输入',
          initialValue: '',
          itemList: []
        }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      let params = Object.assign({}, val, { orgStatus: '25281002', programStatus: '25281002' });
      this.fetchParams = params;
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '方案编号', dataIndex: 'programCode', sorter: true },
        {
          title: '方案状态',
          dataIndex: 'programStatus',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.programStatus, '2528')}</span>;
          }
        },
        {
          title: '方案下发渠道',
          dataIndex: 'programIssuedChannel',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.programIssuedChannel, '2530')}</span>;
          }
        },
        { title: '方案名称', dataIndex: 'programName', sorter: true },
        { title: '事业部名称', dataIndex: 'orgOrgName', sorter: true },
        {
          title: '项目周期',
          dataIndex: 'field6',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          render: props => {
            //编码转汉字
            return (
              <span>
                {formatdateByDay(props.row.projectStartDate)}-{formatdateByDay(props.row.projectEndDate)}
              </span>
            );
          }
        },
        { title: '分配时间', dataIndex: 'distributionTime', dateFormat: 'yyyy-MM-dd', sorter: true }
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      if (this.selectedRows == null || this.selectedRows.length == 0) {
        this.$notify.error({ title: '提示信息', message: '请选择数据!' });
      } else {
        this.$emit('close', { visible: false, data: this.selectedRows });
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false });
    }
  },
  mounted() {
    //this.BaseTable = this.$refs.listModal.$refs.pageTable;
  },
  created() {
    this.getUserInfo();
  }
};
</script>

<style lang="less" scoped>
</style>
